#include <iostream>
#include <memory>

using std::cout;
using std::endl;

class Computer
{
public:
    Computer(){}
    void setboard(const std::string& board)
    {
        this->board=board;
    }
    void setdisplay(const std::string& display)
    {
        this->display=display;
    }
    virtual void setOS()=0;
    void show()
    {
        std::string computer="computer:{\n";
        computer+="\tboard: "+board+",\n";
        computer+="\tdisplay: "+display+",\n";
        computer+="\tOS: "+OS+"\n";
        computer+="}\n";
        
        cout<<computer;
    }
protected:
    std::string board;
    std::string display;
    std::string OS;
};

class Windows:public Computer
{
public:
    void setOS() override
    {
        OS="windows xxx v-1.2.3";
    }
};

class Builder
{
public:
    virtual void buildBoard(const std::string&)=0;
    virtual void buildDisplay(const std::string&)=0;
    virtual void buildOS()=0;
    virtual std::shared_ptr<Computer> build()=0;
};

class WindowsBuilder:public Builder
{
public:
    WindowsBuilder():computer(new Windows){}
    void buildBoard(const std::string& board)
    {
        computer->setboard(board);
    }
    void buildDisplay(const std::string& display)
    {
        computer->setdisplay(display);
    }
    void buildOS()
    {
        computer->setOS();
    }
    std::shared_ptr<Computer> build()
    {
        return computer;
    }
private:
    std::shared_ptr<Computer> computer;
};

class Director
{
public:
    Director(Builder* wb):builder(wb){}
    void construct(const std::string& board,const std::string& display)
    {
        builder->buildBoard(board);
        builder->buildDisplay(board);
        builder->buildOS();
    }
private:
    std::shared_ptr<Builder> builder;
};
int main()
{
    Builder* bw=new WindowsBuilder();
    std::unique_ptr<Director> pd(new Director(bw));
    pd->construct("intel主板","三星显示器");

    std::shared_ptr<Computer> computer= bw->build();
    computer->show();
    
    return 0;
}